<!--反馈管理-->
<?php

use yii\widgets\LinkPager;
use yii\helpers\Url;
use common\service\ConstatService ;
use backend\service\AuthService ;
use common\service\UtilService ;

$pageName = "售后报修单";

$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$this->title = $pageName . "-" . Yii::$app->params['webname'];
$this->params['breadcrumbs'][] = $pageName;
$this->params['display_name'] = $pageName;
$getData = Yii::$app->request->get();
$statusArr = ConstatService::FEED_STATIC_COLOR_ARR;
$verifyArr = ConstatService::FEED_VERIFY_ARR ;
$userId = Yii::$app->admin->identity->user_id ;
$typeId = Yii::$app->admin->identity->type_id ;
$not_deal_num = empty($feedArr['not_deal_num'])?0:$feedArr['not_deal_num'];
$dealing_num = empty($feedArr['dealing_num'])?0:$feedArr['dealing_num'];

$isMobile = UtilService::isMobile() ;

?>

<div class="row">
    <div class="col-md-12">
        <div class="nav-tabs-custom">
            <form id="search_form" style="padding-top: 36px"method="get" action="<?= Url::toRoute(["feed/index"]) ?>">
                <div class="form-group row" style="padding: 0 19px">
                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0" >状态：</label>
                    <div class="col-sm-1" style="padding: 1px">
                        <select class="form-control" name="status" id="search_status">
                            <option value="-1">全部</option>
                            <?php foreach ($statusArr as $key => $val) : ?>
                                <option value="<?= $key ?>"><?= $val ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>

                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0">审核状态：</label>
                    <div class="col-sm-1" style="padding: 1px">
                        <select class="form-control" name="verify" id="search_verify">
                            <option value="-1">全部</option>
                            <?php foreach ($verifyArr as $key => $val) : ?>
                                <option value="<?= $key ?>"><?= $val ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                </div>

                <div class="form-group row" style="padding: 0 19px">
                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0" >公司名：</label>
                    <div class="col-sm-1" style="padding: 1px">
                        <input class="form-control" name="company_name" id="search_company_name"  value="<?=empty($getData['company_name']) ? '' :$getData['company_name']?>" >
                    </div>

                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0" for="w0">反馈时间：</label>
                    <div class="col-sm-5" style="padding: 1px">
                        <div style="display: inline-block;<?php if($isMobile==false):?> width: 220px;  <?php endif;?>  font-size: 10px">
                            <?= \dosamigos\datepicker\DatePicker::widget([
                                'name' => 'add_time_strart',
                                'language' => 'zh-CN',
                                'value' => empty($getData['add_time_strart']) ? '' :$getData['add_time_strart'] ,
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                ],
                            ]);?>
                        </div>

                        <div style="display: inline-block;<?php if($isMobile==false):?> width: 220px; margin-left: 20px; <?php endif;?> font-size: 10px">
                            <?= \dosamigos\datepicker\DatePicker::widget([
                                'name' => 'add_time_end',
                                'language' => 'zh-CN',
                                'value' => empty($getData['add_time_end']) ?'' : $getData['add_time_end'] ,
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                ],
                            ]);?>
                        </div>
                    </div>

                    <div class="col-sm-2 pull-left">
                        <button class="btn btn-primary" type="submit">搜索</button>
                        <?php if(AuthService::checkUserAuth($userId,"feed/export")):?>
                            <a href="javascript:void(0)" class="btn btn-success button-order-export-excel">导出</a>
                        <?php endif;?>
                    </div>
                </div>

            </form>
            <div style="border-bottom: 1px solid #ccc; padding: 19px">
                <div style="float: left; color: #666">共  <?= $feedArr['page']->totalCount ?> 条记录</div>

                <div class="form-group">
                    <?php if(AuthService::checkUserAuth($userId,"feed/add-feed")):?>
                    <button id="add_new" class="btn btn-primary btn-xs pull-right btn-hide button-add-feed" title="添加" type="button"><i class="fa fa-plus"></i>添加</button>
                    <?php endif;?>
                </div>

            </div>

            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-bordered table-striped table-condensed">
                            <tbody>
                                <tr>
                                    <th align="center">序号</th>
                                    <th align="center">状态</th>
                                    <?php if($isMobile):?>
                                    <th align="center">操作</th>
                                    <?php endif;?>
                                    <th align="center">公司名称</th>
                                    <th align="center">描述</th>
                                    <th align="center">处理人</th>
                                    <th align="center">备注</th>
                                    <th align="center">时间</th>
                                    <th align="center">操作</th>
                                </tr>
                                <?php $page = empty($feedArr['page']->getPage())?0:$feedArr['page']->getPage() ;?>
                                <?php $pageSize = empty($feedArr['page']->pageSize)?$limit:$feedArr['page']->pageSize ;?>
                                <?php $pageSize = $page * $pageSize ; ?>
                                <?php foreach ($feedArr['list'] as $key=>$value):?>
                                <tr>
                                    <td><?= $pageSize+$key+1?></td>

                                    <td><?= empty($statusArr[$value['static']])?"":$statusArr[$value['static']]; ?></td>

                                    <?php if($isMobile):?>
                                    <td>
                                        <?php if(AuthService::checkUserAuth($userId,"feed/detail")):?>
                                            <?php $detailUrl = Url::to(["/feed/detail","id"=>$value['id']])?>
                                            <a href="<?=$detailUrl?>" class="btn btn-primary btn-xs">查看</a>
                                        <?php endif;?>
                                    </td>
                                    <?php endif;?>

                                    <td><?= mb_substr($value['company_name'],0,6); ?></td>
                                    <td><?= mb_substr($value['desc'],0,8); ?><?php if(mb_strlen($value['desc'])>8):?>...<?php endif;?></td>
                                    <td><?= $value['deal_user_name']; ?></td>
                                    <td><?= mb_substr($value['remark'],0,8); ?></td>
                                    <!--<td><?= empty($verifyArr[$value['verify']])?"":$verifyArr[$value['verify']]; ?></td>-->
                                    <td><?= date("Y-m-d",strtotime($value['add_time'])); ?></td>
                                    <td>
                                        <?php if(AuthService::checkUserAuth($userId,"feed/detail")):?>
                                        <?php $detailUrl = Url::to(["/feed/detail","id"=>$value['id']])?>
                                        <a href="<?=$detailUrl?>" class="btn btn-primary btn-xs">查看</a>
                                        <?php endif;?>

                                        <?php if(AuthService::checkUserAuth($userId,"feed/edit-feed")):?>
                                            <?php $editUrl = Url::to(["/feed/edit-feed","id"=>$value['id']])?>
                                            <button class="btn btn-success btn-xs edit btn-hide button-edit-feed" title="修改" type="button" data-id="<?= $value['id']?>">修改</button>
                                        <?php endif;?>

                                        <?php if($value['static']!=ConstatService::FEED_STATIC_DEALED):?>
                                        <?php if(AuthService::checkUserAuth($userId,"feed/finish")):?>
                                        <?php $finishUrl = Url::to(["/feed/finish","id"=>$value['id']])?>
                                        <a href="javascript:;" url="<?=$finishUrl?>" class="btn btn-warning btn-xs btn-finish">完成</a>
                                        <?php endif;?>
                                        <?php endif ;?>

                                        <?php if($value['verify']==1):?>
                                            <?php if(AuthService::checkUserAuth($userId,"feed/verify")):?>
                                                <?php $verifyUrl = Url::to(["/feed/verify","id"=>$value['id']])?>
                                                <a href="javascript:ajaxMakedo('<?=$verifyUrl?>', '确认审核？')" class="btn btn-success btn-xs">审核</a>
                                            <?php endif;?>
                                        <?php endif;?>

                                        <?php if(AuthService::checkUserAuth($userId,"feed/del")):?>
                                        <?php $delUrl = Url::to(["/feed/del","id"=>$value['id']])?>
                                        <a href="javascript:ajaxMakedo('<?=$delUrl?>', '确认删除？')" class="btn btn-danger btn-xs">删除</a>
                                        <?php endif;?>

                                        <?php if($value['static']==ConstatService::FEED_STATIC_DEALED):?>
                                        <?php if(AuthService::checkUserAuth($userId,"feed/history")):?>
                                        <?php $detailUrl = Url::to(["/feed/history","id"=>$value['id']])?>
                                        <a href="<?=$detailUrl?>" class="btn btn-primary btn-xs">评价结果</a>
                                        <?php endif;?>
                                        <?php endif ;?>

                                    </td>
                                </tr>
                                <?php  endforeach;?>
                                <tr>
                                    <td colspan="20" class="">
                                        <?=
                                        LinkPager::widget([
                                            'firstPageLabel' => '首页',
                                            'lastPageLabel' => '末页',
                                            'prevPageLabel' => '上一页',
                                            'nextPageLabel' => '下一页',
                                            'pagination' => $feedArr['page'],
                                            'maxButtonCount' => 8,
                                        ])
                                        ?>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div style="display: none"><audio src="/dist/mp3/tip.mp3" controls="controls" id="tip"></audio></div>
<script>
    $(function(){
        $("#myModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        }) ;

        $('#add_new').click(function () {
            var options = {remote: '<?= Url::toRoute('add-feed') ?>'};
            $('#myModal').modal(options)
        });

        $('.button-edit-feed').click(function () {
            var feed_id = $(this).data('id');
            var options = {remote: '<?= Url::toRoute('edit-feed') ?>' + '?id=' + feed_id};
            $('#myModal').modal(options)
        });

        var searchGetData = <?= json_encode(Yii::$app->request->get()) ?>;

        if (searchGetData.status||searchGetData.verify) {
            $.each(searchGetData, function (key, value) {
                $('#search_' + key + ' option[value="' + value + '"]').attr('selected', 'selected');
            });
        }


        $('.btn-finish').click(function () {
            var url = $(this).attr('url');
            $.ajax({
                type: "POST",
                url: url,
                success: function(data){
                    if(data.code==200){
                        var imgurl = data.url ;
                        console.log(imgurl);
                        var tmpHtml = '<div class="modal-header">\n' +
                            '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n' +
                            '                <h4 class="modal-title"></h4>\n' +
                            '            </div>\n' +
                            '            <div class="modal-body" style="text-align:center">\n' +
                            '                <img src="'+imgurl+'" />\n' +
                            '            </div>'
                        $("#myModal").find(".modal-content").html(tmpHtml);
                        $('#myModal').modal('show');
                    }else{
                        bootboxAlert(data.msg);
                    }
                },
                error: function (data) {
                    if (data.status !=  302) {
                        bootboxAlert(data.responseText);
                    }
                }
            });
        });


        $('.button-order-export-excel').click(function () {
            var query = $('#search_form').serialize();
            var url = '<?= Url::toRoute(["/feed/export"]) ?>?' + query;
            $.ajax({
                type: "POST",
                url: url,
                success: function(data){
                    if (typeof(data.code) != "undefined" && data.code == 200) {
//                        console.log(data.url + '?' + query);return;
                        window.open(data.url + '?' + query);
                    } else if (typeof(data.code) != "undefined") {
                        bootboxAlert(data.msg);
                    } else {
                        bootboxAlert('连接异常! ');
                        console.log(data)
                    }
                },
                error: function (data) {
                    if (data.status !=  302) {
                        bootboxAlert(data.responseText);
                    }
                }
            });
        });

        var num = '<?=$not_deal_num ?>' ;
        var dealing_num = '<?=$dealing_num?>' ;

        <?php if($typeId==ConstatService::ADMIN_USER_TYPE_ID_MANAGER):?>
        if(num>0){
            playVoice(num) ;
        }
        <?php endif;?>

        <?php if($typeId==ConstatService::ADMIN_USER_TYPE_ID_GENERAL):?>
        if(dealing_num>0){
            playVoice(dealing_num) ;
        }
        <?php endif;?>



        function myrefresh(){
            window.location.reload();
        }

        <?php if($typeId==ConstatService::ADMIN_USER_TYPE_ID_MANAGER || $typeId==ConstatService::ADMIN_USER_TYPE_ID_GENERAL):?>
        //定时刷新
        setInterval(function(){
            myrefresh();
        }, 360000);
        <?php endif;?>

        function playVoice(num){
            var audio = document.getElementById('tip');
            if(audio!==null) {
                if (audio.paused) {
                    audio.play();// 播放
                } else {
                    audio.pause();// 暂停
                }
            }
            bootboxAlert("您有"+num+"条反馈未处理");
        }

        $(".user-menu").click(function(){
            $(".user-menu").addClass("open");
        })

    });

</script>